import request from "@/libs/request";
import BaseResponse = API.BaseResponse;

/** addMoodPost POST /api/rice/mood/add */
export async function addMoodPost(
  postData: API.MoodAddRequest,
  files?: File[],
  options?: { [key: string]: any },
) {
  const formData = new FormData();
  
  // 添加帖子数据
  formData.append('postData', JSON.stringify(postData));
  
  // 添加多文件（如果有）
  if (files && files.length > 0) {
    files.forEach(file => formData.append('files', file));
  }
  
  return request<API.BaseResponselong>("/api/rice/mood/add", {
    method: "POST", 
    data: formData,
    ...(options || {}),
  });
}

/** showMoodPost POST /api/rice/mood/show */
export async function showMoodPost(
  body: API.UserShowMoodPostRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseListMap>("/api/rice/mood/show", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    data: body,
    ...(options || {}),
  });
}

/**
 * 心情帖子点赞 / 取消点赞
 */
export async function postDoThumb(
  postId: number,
): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/thumb", {
    method: "POST",
    data: { postId },
  });
}

/**
 * 心情帖子点赞 数量
 */
export async function getPostThumbNum(
  postId: number,
): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/thumb/count", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}

/**
 * 心情帖子是否点赞
 * @return resultNum 是否点赞 1：点赞 -1：未点赞
 */
export async function getPostThumbYesNo(
  postId: number,
): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/thumb/yesno", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}

/**
 * 心情帖子点赞好友列表
 * @return resultNum 已点赞用户列表 显示前10位点赞好友
 */
export async function getPostThumbYes(
  postId: number,
): Promise<API.BaseResponseListMap> {
  return request("/api/rice/mood/thumb/yes", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}

/**
 * 心情帖子评论 一二级评论
 *
 */
export async function postDoComment(
  postId: number,
  comment: String,
  parentId: number,
  replyUserId: number,
  replyAccount: String,
): Promise<BaseResponse<boolean>> {
  return request("/api/rice/mood/comment", {
    method: "POST",
    params: { postId, comment, parentId, replyUserId, replyAccount },
    data: { postId, comment, parentId, replyUserId, replyAccount },
  });
}

/**
 * 心情帖子评论 一级评论id查询
 *
 */

/*export async function queryMoodPostCommentId(postId: number,comment:String ): Promise<BaseResponse<number>> {
    return request('/api/rice/mood/comment/id', {
        method: 'POST',
        params: { postId ,comment},
        data: { postId ,comment},
    });
}*/

/**
 * 今日心情帖子一二评论展示
 *
 */
export async function showMoodPostComment(
  postId: number,
): Promise<API.BaseResponseListMap> {
  return request("/api/rice/mood/show/comment", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}

/**
 * 心情帖子评论点赞
 */
export async function postDoCommentThumb(
  commentId: number,
): Promise<BaseResponse<boolean>> {
  return request("/api/rice/mood/comment/thumb", {
    method: "POST",
    data: { commentId },
  });
}

/**
 * 心情帖子评论点赞 数量
 */
export async function getPostCommentThumbNum(
    commentId: number,
): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/comment/thumb/count", {
    method: "POST",
    params: { commentId },
    data: { commentId },
  });
}

/**
 * 心情帖子评论是否点赞
 * @return resultNum 是否点赞 1：点赞 -1：未点赞
 */
export async function getPostCommentThumbYesNo(
    commentId: number,
): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/comment/thumb/yesno", {
    method: "POST",
    params: { commentId },
    data: { commentId },
  });
}

/**
 * 心情帖子总评论 数量
 */
export async function getPostCommentNum(
    postId: number,
): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/comment/count", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}


/**
 * 心情帖子删除评论 删除一二级评论
 *
 */
export async function postDoCommentDelete(
    postId: number,
    commentId: number,
): Promise<BaseResponse<boolean>> {
  return request("/api/rice/mood/comment/delete", {
    method: "POST",
    params: { postId,commentId },
    data: { postId,commentId },
  });
}

/**
 * 心情帖子删除帖子
 *
 */
export async function postDoPostDelete(
    postId: number,
): Promise<BaseResponse<boolean>> {
  return request("/api/rice/mood/post/delete", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}

/**
 * 获取单个心情帖子详情
 */
export async function getMoodPostDetail(
  postId: number,
): Promise<API.BaseResponseListMap> {
  return request("/api/rice/mood/detail", {
    method: "POST",
    params: { postId },
    data: { postId },
  });
}

/**
 * 获取用户饭点帖子数量
 */
export async function getUserMoodPostCount(): Promise<BaseResponse<number>> {
  return request("/api/rice/mood/count", {
    method: "POST",
  });
}
